package org.jeecg.modules.zcgl.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.poi.ss.formula.functions.T;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.activiti.entity.ActBusiness;
import org.jeecg.modules.activiti.service.IActBusinessService;
import org.jeecg.modules.zcgl.entity.*;
import org.jeecg.modules.zcgl.mapper.AssetFixedMapper;
import org.jeecg.modules.zcgl.service.*;
import org.jeecg.modules.zcgl.vo.AssetFixedVo;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: 固定资产
 * @Author: jeecg-boot
 * @Date: 2021-06-30
 * @Version: V1.0
 */
@Service
public class AssetFixedServiceImpl extends ServiceImpl<AssetFixedMapper, AssetFixed> implements IAssetFixedService {

    @Autowired
    private IAssetFixedOperationService assetFixedOperationService;
    @Autowired
    private IAssetFixedLogService assetFixedLogService;
    @Autowired
    private IAssetFixedMaintenanceService assetFixedMaintenanceService;

    @Autowired
    private AssetFixedMapper assetFixedMapper;


    @Autowired
    private IAssetFixedCategoryService assetFixedCategoryService;


    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @Override
    @Transactional
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response, Class<AssetFixed> clazz) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<AssetFixed> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
                int add = 0;
                int edit = 0;
                for (int i = 0; i < list.size(); i++) {
                    AssetFixed assetFixed = list.get(i);

                    if (assetFixed.getName() == null || "".equals(assetFixed.getName())) {

                        return Result.error("文件导入失败:" + "物资名称不能为空");

                    }

//                    if (assetFixed.getAssetType().contains("BGYP")) {
                    if (true) {


                        int count = assetFixedMapper.getTypeCount(assetFixed.getAssetType()) + 1;
                        List<String> list1 = new ArrayList<String>();
                        if (String.valueOf(count).length() < 4) {
                            for (int j = 0; j < 4 - String.valueOf(count).length(); j++) {
                                list1.add("0");
                            }
                        }
                        String result = list1.toString().replace("[", "").replace("]", "") + String.valueOf(count);


                        if (assetFixed.getAssetType().contains("BGYP")) {
                            //如果是办公用品的话，需要使用小类别的编码
                            if (assetFixed.getBgypType() == null) {
                                return Result.error("文件导入失败:" + "办公类别必须设置小类别");
                            }
                            assetFixed.setCode(assetFixed.getBgypType() + "-" + result.replace(", ", ""));
                        } else if ((assetFixed.getAssetType().contains("CHWZ"))) {

                            if (assetFixed.getChwzType() == null) {
                                return Result.error("文件导入失败:" + "存货物资必须设置小类别");
                            }
                            assetFixed.setCode(assetFixed.getChwzType() + "-" + result.replace(", ", ""));

                        } else {
                            if (assetFixed.getBgypType() != null) {
                                return Result.error("文件导入失败:" + "不是办公类别不能设置小类别");
                            }
                            if (assetFixed.getChwzType() != null) {
                                return Result.error("文件导入失败:" + "不是存货物资不能设置小类别");
                            }
                            assetFixed.setCode(assetFixed.getAssetType() + "-" + result.replace(", ", ""));
                        }

                        assetFixed.setPrice(new BigDecimal(0.0));
                        assetFixed.setAmount(new BigDecimal(0.0));

                        //如果规格为空
                        if (assetFixed.getSpecifications() != null && !"".equals(assetFixed.getSpecifications())) {
                            AssetFixed assetFixed1 = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed.getName()).eq("asset_Type", assetFixed.getAssetType()).eq("specifications", assetFixed.getSpecifications()).eq("del_flag", 0).last("and (asset_fixed_category_id is null   or  asset_fixed_category_id = '')"));

                            if (assetFixed1 == null) {
                                assetFixedMapper.insert(assetFixed);
                                add++;
                            } else {
                                assetFixedMapper.updateById(assetFixed1);
                                edit++;
                            }
                        } else {
                            AssetFixed assetFixed1 = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed.getName()).eq("del_flag", 0).eq("asset_Type", assetFixed.getAssetType()).last("and (asset_fixed_category_id is null   or  asset_fixed_category_id = '')"));

                            if (assetFixed1 == null) {
                                assetFixedMapper.insert(assetFixed);
                                add++;
                            } else {
                                assetFixedMapper.updateById(assetFixed1);
                                edit++;
                            }
                        }

                    } else {

//                        if (assetFixed.getCode() == null) {
//
//                            return Result.error("文件导入失败:" + "非办公用品必须设置编码~");
//
//                        }


                        if (assetFixed.getAssetType().contains("BGYP")) {
                            //如果是办公用品的话，需要使用小类别的编码
                            if (assetFixed.getBgypType() == null) {
                                return Result.error("文件导入失败:" + "办公类别必须设置小类别");
                            }
                        } else if ((assetFixed.getAssetType().contains("CHWZ"))) {

                            if (assetFixed.getChwzType() == null) {
                                return Result.error("文件导入失败:" + "存货物资必须设置小类别");
                            }

                        } else {
                            if (assetFixed.getBgypType() != null) {
                                return Result.error("文件导入失败:" + "不是办公类别不能设置小类别");
                            }
                            if (assetFixed.getChwzType() != null) {
                                return Result.error("文件导入失败:" + "不是存货物资不能设置小类别");
                            }
                        }

                        assetFixed.setPrice(new BigDecimal(0.0));
                        assetFixed.setAmount(new BigDecimal(0.0));

                        //如果规格为空
                        if (assetFixed.getSpecifications() != null && !"".equals(assetFixed.getSpecifications())) {
                            AssetFixed assetFixed1 = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed.getName()).eq("asset_Type", assetFixed.getAssetType()).eq("specifications", assetFixed.getSpecifications()).eq("del_flag", 0).last("and (asset_fixed_category_id is null   or  asset_fixed_category_id = '')"));

                            if (assetFixed1 == null) {
                                assetFixedMapper.insert(assetFixed);
                                add++;
                            } else {
                                assetFixedMapper.updateById(assetFixed1);
                                edit++;
                            }
                        } else {
                            AssetFixed assetFixed1 = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed.getName()).eq("del_flag", 0).eq("asset_Type", assetFixed.getAssetType()).last("and (asset_fixed_category_id is null   or  asset_fixed_category_id = '')"));

                            if (assetFixed1 == null) {
                                assetFixedMapper.insert(assetFixed);
                                add++;
                            } else {
                                assetFixedMapper.updateById(assetFixed1);
                                edit++;
                            }
                        }
                    }


                }
                //update-begin-author:taoyan date:20190528 for:批量插入数据
                long start = System.currentTimeMillis();
                //400条 saveBatch消耗时间1592毫秒  循环插入消耗时间1947毫秒
                //1200条  saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
                //update-end-author:taoyan date:20190528 for:批量插入数据
                return Result.ok("文件新增数据行数：" + add + ";文件修改数据行数：" + edit);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.error("文件导入失败！");
    }

    @Autowired
    private IActBusinessService actBusinessService;

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @Override
    @Transactional
    public Result<?> importExcelAssetLY(HttpServletRequest request, HttpServletResponse response, Class<AssetFixedLYImport> clazz) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<AssetFixedLYImport> newList = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
                System.out.println(newList + "文档内容");
                int add = 0;
                int edit = 0;
                List resultList = new ArrayList();
                for (int i = 0; i < newList.size(); i++) {
                    AssetFixedLYImport assetFixed2 = newList.get(i);

                    if(assetFixed2.getName()!=null){

                        AssetFixed assetFixed = new AssetFixed();

                        AssetFixedCategory assetFixedCategory = assetFixedCategoryService.getOne(new QueryWrapper<AssetFixedCategory>().eq("name",assetFixed2.getAssetFixedCategoryId()));
                        if(assetFixedCategory == null ){

                            return Result.error(assetFixed2.getAssetFixedCategoryId()+"该仓库不存在！请仔细检查");

                        }


                        if (assetFixed2.getSpecifications() == null) {
                            assetFixed = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed2.getName()).eq("asset_fixed_category_id",assetFixedCategory.getId()).last("and  amount >0 and  specifications is null"));
//                        assetFixed = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed2.getName()).eq("asset_fixed_category_id",assetFixedCategory.getId()).last("and  amount >0"));
                        } else {
                            System.out.println("开始");
                            assetFixed = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed2.getName()).eq("asset_fixed_category_id",assetFixedCategory.getId()).eq("specifications", assetFixed2.getSpecifications()).last("and amount >0"));
                        }
                        if (assetFixed == null) {
                            return Result.error(assetFixed2.getName() + assetFixed2.getSpecifications() + "物料不存在或者库存不足:" + "请仔细检查");
                        }

                        System.out.println(assetFixed+"我日你妈");

                        List<ActBusiness> list = actBusinessService.list(new QueryWrapper<ActBusiness>().eq("status", "1").eq("table_name", "zcgl_recipients").like("data", assetFixed.getId()));
                        if (list.size() > 0) {
                            Double count = 0.0;
                            for (int j = 0; j < list.size(); j++) {
                                ActBusiness actBusiness = list.get(j);
                                JSONObject data = JSON.parseObject(actBusiness.getData());
                                JSONArray jsonArray = data.getJSONArray("zcglRecipientsAssetsList");



                                for (int k = 0; k < jsonArray.size(); k++) {

                                    if (assetFixed.getSpecifications() == null) {
                                        assetFixed.setSpecifications("");
                                    }
                                    if (assetFixed.getSpecifications().equals(jsonArray.getJSONObject(k).get("assetSpecifications").toString())
                                            && assetFixed.getCode().equals(jsonArray.getJSONObject(k).get("assetCode").toString())
                                            && assetFixed.getAssetFixedCategoryId().equals(assetFixedMapper.selectById(jsonArray.getJSONObject(k).get("assetId").toString()).getAssetFixedCategoryId())
                                    ) {
                                        count += Double.valueOf(jsonArray.getJSONObject(k).get("assetAmount").toString());
                                    }
                                }
                            }
                            //显示流程中的数量

                            System.out.println(assetFixed.getAmount()+"我是多少");
                            assetFixed.setLcCount(new BigDecimal(count));
                            //显示可以入库的数量 因为有的在流程中审核，已经被占用数量
                            assetFixed.setTrueCount(assetFixed.getAmount().subtract(new BigDecimal(count)));
                        } else {
                            System.out.println(assetFixed.getAmount()+"我是多少");
                            assetFixed.setTrueCount(assetFixed.getAmount());
                            assetFixed.setLcCount(new BigDecimal(0.0));

                        }

                        assetFixed.setAmount(assetFixed2.getAmount());
//                    assetFixed.setPrice(assetFixed2.getMoney());
                        resultList.add(assetFixed);
                        if (assetFixed.getName() == null || "".equals(assetFixed.getName())) {
                            return Result.error("文件导入失败:" + "物资名称不能为空");
                        }


                    }


                }
                long start = System.currentTimeMillis();

//                resultList   这是返回数据

//
//                for (int i = 0; i < resultList.size(); i++) {
//                    AssetFixed assetFixed = (AssetFixed) resultList.get(i);
//                    List<ActBusiness> list = actBusinessService.list(new QueryWrapper<ActBusiness>().eq("status", "1").eq("table_name", "zcgl_recipients").like("data", assetFixed.getId()));
//                    if (list.size() > 0) {
//                        Double count = 0.0;
//                        for (int j = 0; j < list.size(); j++) {
//                            ActBusiness actBusiness = list.get(j);
//                            JSONObject data = JSON.parseObject(actBusiness.getData());
//                            JSONArray jsonArray = data.getJSONArray("zcglRecipientsAssetsList");
//                            for (int k = 0; k < jsonArray.size(); k++) {
//                                count += Double.valueOf(jsonArray.getJSONObject(k).get("assetAmount").toString());
//                            }
//                        }
//                        //显示流程中的数量
//                        assetFixed.setLcCount(new BigDecimal(count));
//                        //显示可以入库的数量 因为有的在流程中审核，已经被占用数量
//                        assetFixed.setTrueCount(assetFixed.getAmount().subtract(new BigDecimal(count)));
//                    } else {
//                        assetFixed.setTrueCount(assetFixed.getAmount());
//                        assetFixed.setLcCount(new BigDecimal(0.0));
//                    }
//                }

                System.out.println("查看全部数据" + resultList);
                return Result.ok(resultList);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.error("文件导入失败！");

//        for (int i = 0; i < assetFixeds.size(); i++) {
//            AssetFixed assetFixed = assetFixeds.get(i);
//            List<ActBusiness> list = actBusinessService.list(new QueryWrapper<ActBusiness>().eq("status", "1").eq("table_name", "zcgl_recipients").like("data", assetFixed.getId()));
//            if (list.size() > 0) {
//                Double count = 0.0 ;
//                for (int j = 0; j < list.size(); j++) {
//                    ActBusiness actBusiness = list.get(j);
//                    JSONObject data = JSON.parseObject(actBusiness.getData());
//                    JSONArray jsonArray = data.getJSONArray("zcglRecipientsAssetsList");
//                    for (int k = 0; k < jsonArray.size(); k++) {
//                        count += Double.valueOf(jsonArray.getJSONObject(k).get("assetAmount").toString());
//                    }
//                }
//                //显示流程中的数量
//                assetFixed.setLcCount(new BigDecimal(count));
//                //显示可以入库的数量 因为有的在流程中审核，已经被占用数量
//                assetFixed.setTrueCount(assetFixed.getAmount().subtract(new BigDecimal(count)));
//            }else{
//                assetFixed.setTrueCount(assetFixed.getAmount());
//                assetFixed.setLcCount(new BigDecimal(0.0));
//            }
//        }
//        return Result.ok(assetFixeds);
    }


    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @Override
    @Transactional
    public Result<?> importExcelAsset(HttpServletRequest request, HttpServletResponse response, Class<AssetFixedPutImport> clazz) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<AssetFixedPutImport> newList = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
                Set<String> nameSpecSet = new HashSet<>();
                for (AssetFixedPutImport item : newList) {
                    // 生成名称和规格的组合键
                    String key = item.getName() + "|" + item.getSpecifications();
                    // 检查是否已经存在
                    if (nameSpecSet.contains(key)) {
                        throw new Exception("发现重复数据: 名称 = " + item.getName() + ", 规格 = " + item.getSpecifications());
                    }
                    // 将组合键添加到 Set 中
                    nameSpecSet.add(key);
                }



                System.out.println(newList + "文档内容");
                int add = 0;
                int edit = 0;
                List resultList = new ArrayList();
                for (int i = 0; i < newList.size(); i++) {
                    AssetFixedPutImport assetFixed2 = newList.get(i);

                    if(assetFixed2.getName()!=null  &&  assetFixed2.getAmount()!=null   &&  assetFixed2.getMoney()!=null ){


                        AssetFixed assetFixed = new AssetFixed();
                        if (assetFixed2.getSpecifications() == null) {
                            assetFixed = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed2.getName()).eq("del_flag", 0).last("and   specifications is null and asset_fixed_category_id is null"));
                        } else {
                            assetFixed = assetFixedMapper.selectOne(new QueryWrapper<AssetFixed>().eq("name", assetFixed2.getName()).eq("del_flag", 0).eq("specifications", assetFixed2.getSpecifications()).last("and  asset_fixed_category_id is null"));
                        }
                        if (assetFixed == null) {
                            return Result.error(assetFixed2.getName() + assetFixed2.getSpecifications() + "物料不存在:" + "请仔细检查 ");
                        }
                        List<ActBusiness> list = actBusinessService.list(new QueryWrapper<ActBusiness>().eq("status", "1").eq("table_name", "zcgl_recipients").like("data", assetFixed.getId()));
                        if (list.size() > 0) {
                            Double count = 0.0;
                            for (int j = 0; j < list.size(); j++) {
                                ActBusiness actBusiness = list.get(j);
                                JSONObject data = JSON.parseObject(actBusiness.getData());
                                JSONArray jsonArray = data.getJSONArray("zcglRecipientsAssetsList");
                                for (int k = 0; k < jsonArray.size(); k++) {
                                    count += Double.valueOf(jsonArray.getJSONObject(k).get("assetAmount").toString());
                                }
                            }
                            //显示流程中的数量
                            assetFixed.setLcCount(new BigDecimal(count));
                            //显示可以入库的数量 因为有的在流程中审核，已经被占用数量
                            assetFixed.setTrueCount(assetFixed.getAmount().subtract(new BigDecimal(count)));
                        } else {
                            assetFixed.setTrueCount(assetFixed.getAmount());
                            assetFixed.setLcCount(new BigDecimal(0.0));

                        }

                        assetFixed.setAmount(assetFixed2.getAmount());
                        assetFixed.setPrice(assetFixed2.getMoney());
                        resultList.add(assetFixed);
                        if (assetFixed.getName() == null || "".equals(assetFixed.getName())) {
                            return Result.error("文件导入失败:" + "物资名称不能为空");
                        }

                    }


                }
                long start = System.currentTimeMillis();

//                resultList   这是返回数据

                System.out.println("查看全部数据" + resultList);
                return Result.ok(resultList);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.error("文件导入失败！");

//        for (int i = 0; i < assetFixeds.size(); i++) {
//            AssetFixed assetFixed = assetFixeds.get(i);
//            List<ActBusiness> list = actBusinessService.list(new QueryWrapper<ActBusiness>().eq("status", "1").eq("table_name", "zcgl_recipients").like("data", assetFixed.getId()));
//            if (list.size() > 0) {
//                Double count = 0.0 ;
//                for (int j = 0; j < list.size(); j++) {
//                    ActBusiness actBusiness = list.get(j);
//                    JSONObject data = JSON.parseObject(actBusiness.getData());
//                    JSONArray jsonArray = data.getJSONArray("zcglRecipientsAssetsList");
//                    for (int k = 0; k < jsonArray.size(); k++) {
//                        count += Double.valueOf(jsonArray.getJSONObject(k).get("assetAmount").toString());
//                    }
//                }
//                //显示流程中的数量
//                assetFixed.setLcCount(new BigDecimal(count));
//                //显示可以入库的数量 因为有的在流程中审核，已经被占用数量
//                assetFixed.setTrueCount(assetFixed.getAmount().subtract(new BigDecimal(count)));
//            }else{
//                assetFixed.setTrueCount(assetFixed.getAmount());
//                assetFixed.setLcCount(new BigDecimal(0.0));
//            }
//        }
//        return Result.ok(assetFixeds);
    }


    @Override
    public List<AssetFixedVo> getJieXianList() {
        return assetFixedMapper.getJieXianList();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void editAssetFixed(AssetFixed assetFixed) {
        AssetFixed oldAsset = this.getById(assetFixed.getId());
        String oldJsonStr = JSONObject.toJSONString(oldAsset);
        String newJsonStr = JSONObject.toJSONString(assetFixed);
        this.updateById(assetFixed);
        //新增固定资产操作记录
        AssetFixedOperation operation = new AssetFixedOperation();
        operation.setAssetFixedId(assetFixed.getId());
        operation.setOperation("EDIT");
        operation.setOldData(oldJsonStr);
        operation.setNewData(newJsonStr);
        assetFixedOperationService.save(operation);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delAssetFixed(String id) {
        AssetFixed oldAsset = this.getById(id);
        String oldJsonStr = JSONObject.toJSONString(oldAsset);
        this.removeById(id);
        AssetFixedOperation operation = new AssetFixedOperation();
        operation.setAssetFixedId(id);
        operation.setOperation("DELETE");
        operation.setOldData(oldJsonStr);
        assetFixedOperationService.save(operation);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delBatchAssetFixed(String ids) {
        List<AssetFixed> assetFixedList = this.list(new LambdaQueryWrapper<AssetFixed>()
                .in(AssetFixed::getId, Arrays.asList(ids.split(","))));
        List<AssetFixedOperation> operationList = assetFixedList.stream().map(p -> {
            AssetFixedOperation operation = new AssetFixedOperation();
            operation.setAssetFixedId(p.getId());
            operation.setOperation("DELETE");
            operation.setOldData(JSONObject.toJSONString(p));
            return operation;
        }).collect(Collectors.toList());
        assetFixedOperationService.saveBatch(operationList);
        this.removeByIds(Arrays.asList(ids.split(",")));
    }

    @Override
    /**
     * 导出excel
     *
     * @param request
     */
    public ModelAndView exportXls1(HttpServletRequest request, AssetFixed assetFixed1, Class<T> clazz, String title) {
//        // Step.1 组装查询条件
//        QueryWrapper<AssetFixed> queryWrapper = QueryGenerator.initQueryWrapper(assetFixed1, request.getParameterMap());
//
//        //0才是未删除的
//
//        assetFixed1.setDelFlag(0);
//        if("safe".equals(assetFixed1.getSafeType())){
//
//            queryWrapper.apply("amount < jiexian");
//
//        }
//        if("2".equals(type)){
//            queryWrapper.apply("amount >0");
//
//        }
//
//
//        LoginUser sysUser = JwtUtil.getLoginUser();
////        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        System.out.println(sysUser+"到底有东西没");
//
//        // Step.2 获取导出数据
//        List<T> pageList = service.list(queryWrapper);
//        List<T> exportList = null;
//
//        // 过滤选中数据
//        String selections = request.getParameter("selections");
//        if (oConvertUtils.isNotEmpty(selections)) {
//            List<String> selectionList = Arrays.asList(selections.split(CommonConstant.DEFAULT_SEPARATOR));
//            exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
//        } else {
//            exportList = pageList;
//        }
//
//        // Step.3 AutoPoi 导出Excel
//        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
//        mv.addObject(NormalExcelConstants.FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
//        mv.addObject(NormalExcelConstants.CLASS, clazz);
//        System.out.println("我是什么"+sysUser.getRealname());
//        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title));
//        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
//        return mv;
        return null;
    }

    @Override
    public int getTypeCount(String type) {
        return assetFixedMapper.getTypeCount(type);
    }
}
